/*伤害皮肤*/
var status = 0;
var choice;
var type;
var get_type;
var set_type;
var items = Array(//(價格,type,ItemID,批量購買,是否顯示) type : 0 - 贊助點 1 - 點券 2 - 抵用券
	Array(80,0,3015015,false,true),
	Array(80,0,3015016,false,true),Array(80,0,3015017,false,true),Array(80,0,3015018,false,true),
	Array(80,0,3015019,false,true),Array(80,0,3015020,false,true),Array(80,0,3015021,false,true),
	Array(80,0,3015022,false,true),Array(80,0,3015023,false,true),Array(80,0,3015024,false,true),
	Array(80,0,3015025,false,true),Array(80,0,3015026,false,true),Array(150,0,3015565,false,true),
	Array(150,0,3015566,false,true),Array(150,0,3015567,false,true),Array(150,0,3015568,false,true),
	Array(150,0,3015569,false,true),Array(150,0,3015570,false,true),Array(150,0,3015571,false,true),
	Array(150,0,3015572,false,true),Array(150,0,3015564,false,true)
);

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) cm.dispose();
    else {
        if (status == 0 && mode == 0) {
            cm.dispose();
            return;
        } else if (status >= 1 && mode == 0) {
            cm.sendOk("好吧，歡迎下次再次光臨！.");
            cm.dispose();
            return;
        }
        if (mode == 1) status++;
        else status--;
        if (status == 0) {
			if(cm.getPlayer().getGMLevel() >= 1){
				for(var i in items){
					items[i][0] /= 2;
				}
			}
            choices = "請選擇您要購買的道具：\r\n#n#b";
            for (var i = 0; i < items.length; i++) {
				if(items[i][4]){
					type = ((items[i][1]==0)?"贊助點":((items[i][1]==1)?"點券":"抵用券"));
					choices += "\r\n#b#L" + i + "##v" + items[i][2] + "##z" + items[i][2] + "#　#d需要#r" + items[i][0] + "#d" + type +"#k#l";
				}
			}
            cm.sendSimpleS("" + choices,2);
        } else if (status == 1) {
			choice = selection;
			type = ((items[choice][1]==0)?"贊助點":((items[choice][1]==1)?"點券":"抵用券"));
			get_type = ((items[choice][1]==0)?cm.getRMB():((items[choice][1]==1)?cm.getPlayer().getCSPoints(1):cm.getPlayer().getCSPoints(2)));
			if(items[choice][3])
				cm.sendGetNumber("你選擇的商品為#b#v" + items[choice][2] + "#售價為：" + items[choice][0] + type +"/張\r\n請輸入您要購買的數量",1,1,get_type);
			else{
				cm.sendYesNo("你選擇的商品為#b#v" + items[choice][2] + "# #b售價為：#r" + items[choice][0]  +"#b " + type +"#r\r\n\r\n#fs20#請問您確定要購買?");
			}
        } else if (status == 2) {
			type = ((items[choice][1]==0)?"贊助點":((items[choice][1]==1)?"點券":"抵用券"));
			if(items[choice][3])
				fee = selection;
			else
				fee = 1;
            money = fee*items[choice][0];
            if (fee < 0) {
				cm.sendOk("不能輸入0.或者你沒有足夠的"+ type +"!");
				cm.dispose();
            } else if (get_type < money) {
				cm.sendOk("購買失敗，你沒有" + money + type);
				cm.dispose();
            } else {
				((items[choice][1]==0)?cm.setRMB((cm.getRMB()-money)):((items[choice][1]==1)?cm.gainNX(1, -money):cm.gainNX(2, -money)));
				cm.gainItem(items[choice][2], fee);
				cm.sendOk("#b恭喜，購買了#r " + fee + " #b個#r #v" + items[choice][2] + "#\r\n\r\n#r#fs20#"+ type + " #b餘額為:#r " + get_type + " #b點");
				cm.dispose();
            }
        }
    }
}
